Repository navigation
fix(spanner): retry additional transient InternalServerError errors - #19175
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the internal error retry logic in google-cloud-spanner by replacing _check_rst_stream_error with _is_retryable_internal_error to support a broader range of retryable internal error messages. It also consolidates error handling blocks in snapshot.py and adds comprehensive unit and mock server tests. The review feedback highlights two potential issues in _helpers.py: first, a potential KeyError when performing a direct dictionary lookup on allowed_exceptions[exc.__class__] for subclasses of allowed exceptions, which can be resolved by using isinstance checks; second, a potential AttributeError when accessing exception.message directly, which can be avoided by using getattr safely.
Unify and expand retry handling for transient `INTERNAL` gRPC errors across streaming queries/reads and existing retried operations. Previously, stream resumption and unary retry helpers checked slightly different subsets of error messages, causing transient HTTP/2, connection, and authentication backend errors to fail immediately instead of retrying. With this change: - Streaming operations and retried operations share a single check that verifies the error is an `InternalServerError` before matching transient failure messages. - Retries now cover HTTP/2 `INTERNAL_ERROR`, unknown-cause connection closures, and transient authentication backend internal server errors in addition to `RST_STREAM` and unexpected EOS on `DATA` frames. - Non-retryable internal errors still fail immediately without retrying. - Synchronous and asynchronous unit and mock server tests cover both retryable and non-retryable internal error cases.
f73307f to
ec35dc6
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors retry logic for internal errors in the Google Cloud Spanner client by replacing _check_rst_stream_error with a more comprehensive _is_retryable_internal_error predicate. This expands the list of retryable InternalServerError messages to include HTTP/2 internal errors, connection closures, and authentication backend errors, and consolidates exception handling in snapshot stream resumption. Extensive unit and mock server tests are also added. The review feedback suggests improving the exception class lookup in the _retry helper to robustly support subclasses of registered exceptions by dynamically checking inheritance with isinstance instead of performing a direct dictionary lookup on exc.__class__.
| else: | ||
| stream_finished = True | ||
| except ServiceUnavailable: | ||
| del item_buffer[:] |
There was a problem hiding this comment.
why are we removing this?
There was a problem hiding this comment.
It's not 'removed'. It is consolidated into one except block. The ServiceUnavailable error was added to the except on line 180, as both blocks do the same thing.
…19175) Unify and expand retry handling for transient `INTERNAL` gRPC errors across streaming queries/reads and existing retried operations. Previously, stream resumption and unary retry helpers checked slightly different subsets of error messages, causing transient HTTP/2, connection, and authentication backend errors to fail immediately instead of retrying. With this change: - Streaming operations and retried operations share a single check that verifies the error is an `InternalServerError` before matching transient failure messages. - Retries now cover HTTP/2 `INTERNAL_ERROR`, unknown-cause connection closures, and transient authentication backend internal server errors in addition to `RST_STREAM` and unexpected EOS on `DATA` frames. - Non-retryable internal errors still fail immediately without retrying. - Synchronous and asynchronous unit and mock server tests cover both retryable and non-retryable internal error cases.
Unify and expand retry handling for transient
INTERNALgRPC errors across streaming queries/reads and existing retried operations.Previously, stream resumption and unary retry helpers checked slightly different subsets of error messages, causing transient HTTP/2, connection, and authentication backend errors to fail immediately instead of retrying.
With this change:
InternalServerErrorbefore matching transient failure messages.INTERNAL_ERROR, unknown-cause connection closures, and transient authentication backend internal server errors in addition toRST_STREAMand unexpected EOS onDATAframes.